﻿using System.Collections.Generic;
using Tp.Dto;
using Tp.Interfaces;
using Tp.Interfaces.Services;
using Tp.Models;

namespace Tp.Services
{
	public class EmployeeService : IEmployeeService
	{
		#region Fields
		#endregion

		#region CRUD
		public List<EmployeeDto> LoadEmployees()
		{
			var list = new List<EmployeeDto>();
			var employees = new TpOfficeDataClassesDataContext().Employees;

			foreach (var employee in employees)
			{
				var department = new DepartmentDto(
					employee.Department1.Id,
					employee.Department1.Name,
					employee.Department1.Description);

				var title = new TitleDto(
					employee.Title1.Id,
					employee.Title1.Name);

				list.Add(
					new EmployeeDto(
						employee.Id,
						employee.Firstname,
						employee.Lastname,
						employee.DoB,
						employee.Street,
						employee.Hausnumber,
						employee.ZIP,
						employee.City,
						employee.State,
						department,
						title));
			}

			return list;
		}
		#endregion
	}
}
